﻿using System;
using System.Drawing;
using System.Drawing.Printing;
using System.Drawing.Text;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Collections.Generic;

namespace NotepadApp
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
        private PrintDocument printDocument1 = new PrintDocument();
        private System.Windows.Forms.OpenFileDialog ofd;
        private System.Windows.Forms.PrintDialog pd;
        private System.Windows.Forms.SaveFileDialog sfd;
        private System.Windows.Forms.FontDialog fd;
        private System.Windows.Forms.PageSetupDialog psd;
        private ToolStrip tool1;
        private ToolStripButton newToolStripButton;
        private ToolStripButton openToolStripButton;
        private ToolStripButton saveToolStripButton;
        private ToolStripButton printToolStripButton;
        private ToolStripSeparator toolStripSeparator;
        private ToolStripButton cutToolStripButton;
        private ToolStripButton copyToolStripButton;
        private ToolStripButton pasteToolStripButton;
        private ToolStripSeparator toolStripSeparator1;
        private ToolStripButton helpToolStripButton;
        private ToolStripButton toolStripButton8;
        private ToolStripButton tbold;
        private ToolStripButton titalic;
        private ToolStripButton tunderline;
        private ToolStripSeparator toolStripSeparator2;
        private ToolStripButton tcenter;
        private ToolStripButton tleft;
        private ToolStripButton tright;
        private ToolStripSeparator toolStripSeparator3;
        private PrintPreviewDialog printPreviewDialog1;
        private StatusStrip statusStrip1;
        private ToolStripStatusLabel mlabel;
        private ToolStripButton tundo;
        private ToolStripButton tfind;
        private ToolStripLabel toolStripLabel1;
        private Nik.UserControls.RicherTextBox2 txt;
        private ContextMenuStrip contextMenuStrip1;
        private ToolStripMenuItem undoToolStripMenuItem;
        private ToolStripMenuItem cutToolStripMenuItem;
        private ToolStripMenuItem copyToolStripMenuItem;
        private ToolStripMenuItem pasteToolStripMenuItem;
        private ToolStripSeparator toolStripSeparator4;
        private ToolStripMenuItem selectAllToolStripMenuItem;
        private MenuStrip menuStrip1;
        private ToolStripMenuItem mfile;
        private ToolStripMenuItem mnew;
        private ToolStripMenuItem mopen;
        private ToolStripMenuItem msave;
        private ToolStripMenuItem saveAsToolStripMenuItem;
        private ToolStripSeparator toolStripSeparator5;
        private ToolStripMenuItem pageSetupToolStripMenuItem;
        private ToolStripMenuItem printPreviewToolStripMenuItem;
        private ToolStripMenuItem printToolStripMenuItem;
        private ToolStripSeparator toolStripSeparator6;
        private ToolStripMenuItem exitToolStripMenuItem;
        private ToolStripMenuItem editToolStripMenuItem;
        private ToolStripMenuItem mundo;
        private ToolStripMenuItem mcut;
        private ToolStripMenuItem mcopy;
        private ToolStripMenuItem mpaste;
        private ToolStripMenuItem viewToolStripMenuItem;
        private ToolStripMenuItem mtool;
        private ToolStripMenuItem mstatus;
        private ToolStripMenuItem formatToolStripMenuItem;
        private ToolStripMenuItem ww;
        private ToolStripMenuItem fontsToolStripMenuItem;
        private ToolStripMenuItem helpToolStripMenuItem;
        private ToolStripMenuItem mreg;
        private ToolStripMenuItem mabout;
        private RecentsToolStripMenuItem mrecent;
        private ToolStripMenuItem findToolStripMenuItem;
        private IContainer components;
        private ToolStripMenuItem findNextToolStripMenuItem;
        private ToolStripMenuItem replaceToolStripMenuItem;
        private ToolStripMenuItem insertToolStripMenuItem;
        private ToolStripMenuItem mimages;
        private Findform.FindForm _findForm;
        private string stringToPrint;
        private string documentContents;
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            mrecent.UpdateList();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.ofd = new System.Windows.Forms.OpenFileDialog();
            this.pd = new System.Windows.Forms.PrintDialog();
            this.sfd = new System.Windows.Forms.SaveFileDialog();
            this.fd = new System.Windows.Forms.FontDialog();
            this.psd = new System.Windows.Forms.PageSetupDialog();
            this.tool1 = new System.Windows.Forms.ToolStrip();
            this.newToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.openToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.saveToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.printToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.toolStripButton8 = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator = new System.Windows.Forms.ToolStripSeparator();
            this.tundo = new System.Windows.Forms.ToolStripButton();
            this.cutToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.copyToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.pasteToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.tbold = new System.Windows.Forms.ToolStripButton();
            this.titalic = new System.Windows.Forms.ToolStripButton();
            this.tunderline = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
            this.tleft = new System.Windows.Forms.ToolStripButton();
            this.tright = new System.Windows.Forms.ToolStripButton();
            this.tcenter = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
            this.tfind = new System.Windows.Forms.ToolStripButton();
            this.helpToolStripButton = new System.Windows.Forms.ToolStripButton();
            this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
            this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
            this.statusStrip1 = new System.Windows.Forms.StatusStrip();
            this.mlabel = new System.Windows.Forms.ToolStripStatusLabel();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.undoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.cutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.pasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
            this.selectAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.mfile = new System.Windows.Forms.ToolStripMenuItem();
            this.mnew = new System.Windows.Forms.ToolStripMenuItem();
            this.mopen = new System.Windows.Forms.ToolStripMenuItem();
            this.msave = new System.Windows.Forms.ToolStripMenuItem();
            this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator();
            this.pageSetupToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.printPreviewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.printToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
            this.mrecent = new RecentsToolStripMenuItem();
            this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mundo = new System.Windows.Forms.ToolStripMenuItem();
            this.mcut = new System.Windows.Forms.ToolStripMenuItem();
            this.mcopy = new System.Windows.Forms.ToolStripMenuItem();
            this.mpaste = new System.Windows.Forms.ToolStripMenuItem();
            this.findToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.findNextToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.replaceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mtool = new System.Windows.Forms.ToolStripMenuItem();
            this.mstatus = new System.Windows.Forms.ToolStripMenuItem();
            this.formatToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.ww = new System.Windows.Forms.ToolStripMenuItem();
            this.fontsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.insertToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mimages = new System.Windows.Forms.ToolStripMenuItem();
            this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.mreg = new System.Windows.Forms.ToolStripMenuItem();
            this.mabout = new System.Windows.Forms.ToolStripMenuItem();
            this.txt = new Nik.UserControls.RicherTextBox2();
            this.tool1.SuspendLayout();
            this.statusStrip1.SuspendLayout();
            this.contextMenuStrip1.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // sfd
            // 
            this.sfd.FileName = "doc1";
            // 
            // tool1
            // 
            this.tool1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripButton,
            this.openToolStripButton,
            this.saveToolStripButton,
            this.printToolStripButton,
            this.toolStripButton8,
            this.toolStripSeparator,
            this.tundo,
            this.cutToolStripButton,
            this.copyToolStripButton,
            this.pasteToolStripButton,
            this.toolStripSeparator1,
            this.tbold,
            this.titalic,
            this.tunderline,
            this.toolStripSeparator2,
            this.tleft,
            this.tright,
            this.tcenter,
            this.toolStripSeparator3,
            this.tfind,
            this.helpToolStripButton,
            this.toolStripLabel1});
            this.tool1.Location = new System.Drawing.Point(0, 24);
            this.tool1.Name = "tool1";
            this.tool1.Size = new System.Drawing.Size(641, 25);
            this.tool1.TabIndex = 3;
            this.tool1.Text = "toolStrip1";
            // 
            // newToolStripButton
            // 
            this.newToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.newToolStripButton.Image = global::NotepadApp.Properties.Resources.newdocument32;
            this.newToolStripButton.ImageTransparentColor = System.Drawing.SystemColors.Control;
            this.newToolStripButton.Name = "newToolStripButton";
            this.newToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.newToolStripButton.Text = "&New";
            this.newToolStripButton.Click += new System.EventHandler(this.mnew_Click);
            // 
            // openToolStripButton
            // 
            this.openToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.openToolStripButton.Image = global::NotepadApp.Properties.Resources.open16;
            this.openToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.openToolStripButton.Name = "openToolStripButton";
            this.openToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.openToolStripButton.Text = "&Open";
            this.openToolStripButton.Click += new System.EventHandler(this.mopen_Click);
            // 
            // saveToolStripButton
            // 
            this.saveToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.saveToolStripButton.Image = global::NotepadApp.Properties.Resources.save16;
            this.saveToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.saveToolStripButton.Name = "saveToolStripButton";
            this.saveToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.saveToolStripButton.Text = "&Save";
            this.saveToolStripButton.Click += new System.EventHandler(this.msave_Click);
            // 
            // printToolStripButton
            // 
            this.printToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.printToolStripButton.Image = global::NotepadApp.Properties.Resources.print32;
            this.printToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.printToolStripButton.Name = "printToolStripButton";
            this.printToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.printToolStripButton.Text = "&Print";
            this.printToolStripButton.Click += new System.EventHandler(this.mprint_Click);
            // 
            // toolStripButton8
            // 
            this.toolStripButton8.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButton8.Image = global::NotepadApp.Properties.Resources.printpreview32;
            this.toolStripButton8.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButton8.Name = "toolStripButton8";
            this.toolStripButton8.Size = new System.Drawing.Size(23, 22);
            this.toolStripButton8.Text = "toolStripButton8";
            this.toolStripButton8.ToolTipText = "Print Preview";
            this.toolStripButton8.Click += new System.EventHandler(this.mprintpreview_Click);
            // 
            // toolStripSeparator
            // 
            this.toolStripSeparator.Name = "toolStripSeparator";
            this.toolStripSeparator.Size = new System.Drawing.Size(6, 25);
            // 
            // tundo
            // 
            this.tundo.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tundo.Image = global::NotepadApp.Properties.Resources.undo16;
            this.tundo.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tundo.Name = "tundo";
            this.tundo.Size = new System.Drawing.Size(23, 22);
            this.tundo.Text = "&Undo";
            this.tundo.ToolTipText = "Undo";
            this.tundo.Click += new System.EventHandler(this.mundo_Click);
            // 
            // cutToolStripButton
            // 
            this.cutToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.cutToolStripButton.Image = global::NotepadApp.Properties.Resources.cut16;
            this.cutToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.cutToolStripButton.Name = "cutToolStripButton";
            this.cutToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.cutToolStripButton.Text = "C&ut";
            this.cutToolStripButton.Click += new System.EventHandler(this.mcut_Click);
            // 
            // copyToolStripButton
            // 
            this.copyToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.copyToolStripButton.Image = global::NotepadApp.Properties.Resources.copy16;
            this.copyToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.copyToolStripButton.Name = "copyToolStripButton";
            this.copyToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.copyToolStripButton.Text = "&Copy";
            this.copyToolStripButton.Click += new System.EventHandler(this.mcopy_Click);
            // 
            // pasteToolStripButton
            // 
            this.pasteToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.pasteToolStripButton.Image = global::NotepadApp.Properties.Resources.paste16;
            this.pasteToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.pasteToolStripButton.Name = "pasteToolStripButton";
            this.pasteToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.pasteToolStripButton.Text = "&Paste";
            this.pasteToolStripButton.Click += new System.EventHandler(this.mpaste_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
            // 
            // tbold
            // 
            this.tbold.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tbold.Image = global::NotepadApp.Properties.Resources.bold16;
            this.tbold.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tbold.Name = "tbold";
            this.tbold.Size = new System.Drawing.Size(23, 22);
            this.tbold.Text = "Bold";
            this.tbold.ToolTipText = "Bold";
            this.tbold.Click += new System.EventHandler(this.tbold_Click);
            // 
            // titalic
            // 
            this.titalic.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.titalic.Image = global::NotepadApp.Properties.Resources.italic16;
            this.titalic.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.titalic.Name = "titalic";
            this.titalic.Size = new System.Drawing.Size(23, 22);
            this.titalic.Text = "Italic";
            this.titalic.ToolTipText = "Italic";
            this.titalic.Click += new System.EventHandler(this.titalic_Click);
            // 
            // tunderline
            // 
            this.tunderline.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tunderline.Image = global::NotepadApp.Properties.Resources.underline16;
            this.tunderline.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tunderline.Name = "tunderline";
            this.tunderline.Size = new System.Drawing.Size(23, 22);
            this.tunderline.Text = "Underline";
            this.tunderline.ToolTipText = "UNderline";
            this.tunderline.Click += new System.EventHandler(this.tunderline_Click);
            // 
            // toolStripSeparator2
            // 
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
            // 
            // tleft
            // 
            this.tleft.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tleft.Image = global::NotepadApp.Properties.Resources.textalignleft16;
            this.tleft.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tleft.Name = "tleft";
            this.tleft.Size = new System.Drawing.Size(23, 22);
            this.tleft.Text = "toolStripButton6";
            this.tleft.ToolTipText = "Align Left";
            this.tleft.Click += new System.EventHandler(this.tleft_Click);
            // 
            // tright
            // 
            this.tright.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tright.Image = global::NotepadApp.Properties.Resources.textalignright16;
            this.tright.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tright.Name = "tright";
            this.tright.Size = new System.Drawing.Size(23, 22);
            this.tright.Text = "toolStripButton7";
            this.tright.ToolTipText = "Align Right";
            this.tright.Click += new System.EventHandler(this.tright_Click);
            // 
            // tcenter
            // 
            this.tcenter.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tcenter.Image = global::NotepadApp.Properties.Resources.textaligncenter16;
            this.tcenter.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tcenter.Name = "tcenter";
            this.tcenter.Size = new System.Drawing.Size(23, 22);
            this.tcenter.Text = "toolStripButton4";
            this.tcenter.ToolTipText = "Align Center";
            this.tcenter.Click += new System.EventHandler(this.tcenter_Click);
            // 
            // toolStripSeparator3
            // 
            this.toolStripSeparator3.Name = "toolStripSeparator3";
            this.toolStripSeparator3.Size = new System.Drawing.Size(6, 25);
            // 
            // tfind
            // 
            this.tfind.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.tfind.Image = global::NotepadApp.Properties.Resources.find32;
            this.tfind.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.tfind.Name = "tfind";
            this.tfind.Size = new System.Drawing.Size(23, 22);
            this.tfind.Text = "Find";
            this.tfind.Click += new System.EventHandler(this.replaceToolStripMenuItem_Click);
            // 
            // helpToolStripButton
            // 
            this.helpToolStripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.helpToolStripButton.Image = global::NotepadApp.Properties.Resources._1394205579_help;
            this.helpToolStripButton.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.helpToolStripButton.Name = "helpToolStripButton";
            this.helpToolStripButton.Size = new System.Drawing.Size(23, 22);
            this.helpToolStripButton.Text = "He&lp";
            // 
            // toolStripLabel1
            // 
            this.toolStripLabel1.Name = "toolStripLabel1";
            this.toolStripLabel1.Size = new System.Drawing.Size(0, 22);
            // 
            // printPreviewDialog1
            // 
            this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
            this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
            this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
            this.printPreviewDialog1.Enabled = true;
            this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
            this.printPreviewDialog1.Name = "printPreviewDialog1";
            this.printPreviewDialog1.Visible = false;
            // 
            // statusStrip1
            // 
            this.statusStrip1.BackColor = System.Drawing.SystemColors.Control;
            this.statusStrip1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11F, System.Drawing.FontStyle.Italic);
            this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mlabel});
            this.statusStrip1.Location = new System.Drawing.Point(0, 191);
            this.statusStrip1.Name = "statusStrip1";
            this.statusStrip1.Size = new System.Drawing.Size(641, 22);
            this.statusStrip1.TabIndex = 5;
            this.statusStrip1.Text = "statusStrip1";
            // 
            // mlabel
            // 
            this.mlabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F);
            this.mlabel.Name = "mlabel";
            this.mlabel.Size = new System.Drawing.Size(72, 17);
            this.mlabel.Text = "Line 1 Col 1";
            this.mlabel.TextImageRelation = System.Windows.Forms.TextImageRelation.TextBeforeImage;
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.undoToolStripMenuItem,
            this.cutToolStripMenuItem,
            this.copyToolStripMenuItem,
            this.pasteToolStripMenuItem,
            this.toolStripSeparator4,
            this.selectAllToolStripMenuItem});
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(122, 120);
            // 
            // undoToolStripMenuItem
            // 
            this.undoToolStripMenuItem.Name = "undoToolStripMenuItem";
            this.undoToolStripMenuItem.Size = new System.Drawing.Size(121, 22);
            this.undoToolStripMenuItem.Text = "Undo";
            this.undoToolStripMenuItem.Click += new System.EventHandler(this.mundo_Click);
            // 
            // cutToolStripMenuItem
            // 
            this.cutToolStripMenuItem.Name = "cutToolStripMenuItem";
            this.cutToolStripMenuItem.Size = new System.Drawing.Size(121, 22);
            this.cutToolStripMenuItem.Text = "Cut";
            this.cutToolStripMenuItem.Click += new System.EventHandler(this.mcut_Click);
            // 
            // copyToolStripMenuItem
            // 
            this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
            this.copyToolStripMenuItem.Size = new System.Drawing.Size(121, 22);
            this.copyToolStripMenuItem.Text = "Copy";
            this.copyToolStripMenuItem.Click += new System.EventHandler(this.mcopy_Click);
            // 
            // pasteToolStripMenuItem
            // 
            this.pasteToolStripMenuItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
            this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem";
            this.pasteToolStripMenuItem.Size = new System.Drawing.Size(121, 22);
            this.pasteToolStripMenuItem.Text = "Paste";
            this.pasteToolStripMenuItem.Click += new System.EventHandler(this.mpaste_Click);
            // 
            // toolStripSeparator4
            // 
            this.toolStripSeparator4.Name = "toolStripSeparator4";
            this.toolStripSeparator4.Size = new System.Drawing.Size(118, 6);
            // 
            // selectAllToolStripMenuItem
            // 
            this.selectAllToolStripMenuItem.Name = "selectAllToolStripMenuItem";
            this.selectAllToolStripMenuItem.Size = new System.Drawing.Size(121, 22);
            this.selectAllToolStripMenuItem.Text = "Select All";
            this.selectAllToolStripMenuItem.Click += new System.EventHandler(this.selectAllToolStripMenuItem_Click);
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mfile,
            this.editToolStripMenuItem,
            this.viewToolStripMenuItem,
            this.formatToolStripMenuItem,
            this.insertToolStripMenuItem,
            this.helpToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(641, 24);
            this.menuStrip1.TabIndex = 11;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // mfile
            // 
            this.mfile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mnew,
            this.mopen,
            this.msave,
            this.saveAsToolStripMenuItem,
            this.toolStripSeparator5,
            this.pageSetupToolStripMenuItem,
            this.printPreviewToolStripMenuItem,
            this.printToolStripMenuItem,
            this.toolStripSeparator6,
            this.mrecent,
            this.exitToolStripMenuItem});
            this.mfile.Name = "mfile";
            this.mfile.Size = new System.Drawing.Size(35, 20);
            this.mfile.Text = "File";
            // 
            // mnew
            // 
            this.mnew.Name = "mnew";
            this.mnew.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.N)));
            this.mnew.Size = new System.Drawing.Size(142, 22);
            this.mnew.Text = "New";
            this.mnew.Click += new System.EventHandler(this.mnew_Click);
            // 
            // mopen
            // 
            this.mopen.Name = "mopen";
            this.mopen.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
            this.mopen.Size = new System.Drawing.Size(142, 22);
            this.mopen.Text = "Open";
            this.mopen.Click += new System.EventHandler(this.mopen_Click);
            // 
            // msave
            // 
            this.msave.Name = "msave";
            this.msave.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S)));
            this.msave.Size = new System.Drawing.Size(142, 22);
            this.msave.Text = "Save";
            this.msave.Click += new System.EventHandler(this.msave_Click);
            // 
            // saveAsToolStripMenuItem
            // 
            this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem";
            this.saveAsToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F12;
            this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
            this.saveAsToolStripMenuItem.Text = "Save As";
            this.saveAsToolStripMenuItem.Click += new System.EventHandler(this.msaveas_Click);
            // 
            // toolStripSeparator5
            // 
            this.toolStripSeparator5.Name = "toolStripSeparator5";
            this.toolStripSeparator5.Size = new System.Drawing.Size(139, 6);
            // 
            // pageSetupToolStripMenuItem
            // 
            this.pageSetupToolStripMenuItem.Name = "pageSetupToolStripMenuItem";
            this.pageSetupToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
            this.pageSetupToolStripMenuItem.Text = "Page Setup";
            this.pageSetupToolStripMenuItem.Click += new System.EventHandler(this.mpagesetup_Click);
            // 
            // printPreviewToolStripMenuItem
            // 
            this.printPreviewToolStripMenuItem.Name = "printPreviewToolStripMenuItem";
            this.printPreviewToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
            this.printPreviewToolStripMenuItem.Text = "Print Preview";
            this.printPreviewToolStripMenuItem.Click += new System.EventHandler(this.mprintpreview_Click);
            // 
            // printToolStripMenuItem
            // 
            this.printToolStripMenuItem.Name = "printToolStripMenuItem";
            this.printToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P)));
            this.printToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
            this.printToolStripMenuItem.Text = "Print";
            this.printToolStripMenuItem.Click += new System.EventHandler(this.mprint_Click);
            // 
            // toolStripSeparator6
            // 
            this.toolStripSeparator6.Name = "toolStripSeparator6";
            this.toolStripSeparator6.Size = new System.Drawing.Size(139, 6);
            // 
            // mrecent
            // 
            this.mrecent.Enabled = false;
            this.mrecent.Name = "mrecent";
            this.mrecent.Size = new System.Drawing.Size(142, 22);
            this.mrecent.Text = "Recent Files";
            this.mrecent.ItemClick += new System.EventHandler(this.mrecent_ItemClick);
            // 
            // exitToolStripMenuItem
            // 
            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4)));
            this.exitToolStripMenuItem.Size = new System.Drawing.Size(142, 22);
            this.exitToolStripMenuItem.Text = "Exit";
            this.exitToolStripMenuItem.Click += new System.EventHandler(this.mexit_Click);
            // 
            // editToolStripMenuItem
            // 
            this.editToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mundo,
            this.mcut,
            this.mcopy,
            this.mpaste,
            this.findToolStripMenuItem});
            this.editToolStripMenuItem.Name = "editToolStripMenuItem";
            this.editToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.editToolStripMenuItem.Text = "Edit";
            // 
            // mundo
            // 
            this.mundo.Name = "mundo";
            this.mundo.Size = new System.Drawing.Size(104, 22);
            this.mundo.Text = "Undo";
            this.mundo.Click += new System.EventHandler(this.mundo_Click);
            // 
            // mcut
            // 
            this.mcut.Name = "mcut";
            this.mcut.Size = new System.Drawing.Size(104, 22);
            this.mcut.Text = "Cut";
            this.mcut.Click += new System.EventHandler(this.mcut_Click);
            // 
            // mcopy
            // 
            this.mcopy.Name = "mcopy";
            this.mcopy.Size = new System.Drawing.Size(104, 22);
            this.mcopy.Text = "Copy";
            this.mcopy.Click += new System.EventHandler(this.mcopy_Click);
            // 
            // mpaste
            // 
            this.mpaste.Name = "mpaste";
            this.mpaste.Size = new System.Drawing.Size(104, 22);
            this.mpaste.Text = "Paste";
            this.mpaste.Click += new System.EventHandler(this.mpaste_Click);
            // 
            // findToolStripMenuItem
            // 
            this.findToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.findNextToolStripMenuItem,
            this.replaceToolStripMenuItem});
            this.findToolStripMenuItem.Name = "findToolStripMenuItem";
            this.findToolStripMenuItem.Size = new System.Drawing.Size(104, 22);
            this.findToolStripMenuItem.Text = "Find";
            // 
            // findNextToolStripMenuItem
            // 
            this.findNextToolStripMenuItem.Name = "findNextToolStripMenuItem";
            this.findNextToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
            this.findNextToolStripMenuItem.Text = "Find Next";
            this.findNextToolStripMenuItem.Click += new System.EventHandler(this.findToolStripMenuItem_Click);
            // 
            // replaceToolStripMenuItem
            // 
            this.replaceToolStripMenuItem.Name = "replaceToolStripMenuItem";
            this.replaceToolStripMenuItem.Size = new System.Drawing.Size(122, 22);
            this.replaceToolStripMenuItem.Text = "Replace";
            this.replaceToolStripMenuItem.Click += new System.EventHandler(this.replaceToolStripMenuItem_Click);
            // 
            // viewToolStripMenuItem
            // 
            this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mtool,
            this.mstatus});
            this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
            this.viewToolStripMenuItem.Size = new System.Drawing.Size(42, 20);
            this.viewToolStripMenuItem.Text = "View";
            // 
            // mtool
            // 
            this.mtool.Checked = true;
            this.mtool.CheckState = System.Windows.Forms.CheckState.Checked;
            this.mtool.Name = "mtool";
            this.mtool.Size = new System.Drawing.Size(126, 22);
            this.mtool.Text = "Toolbar";
            this.mtool.Click += new System.EventHandler(this.mtool_Click);
            // 
            // mstatus
            // 
            this.mstatus.Checked = true;
            this.mstatus.CheckState = System.Windows.Forms.CheckState.Checked;
            this.mstatus.Name = "mstatus";
            this.mstatus.Size = new System.Drawing.Size(126, 22);
            this.mstatus.Text = "Status Bar";
            this.mstatus.Click += new System.EventHandler(this.mstatus_Click);
            // 
            // formatToolStripMenuItem
            // 
            this.formatToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.ww,
            this.fontsToolStripMenuItem});
            this.formatToolStripMenuItem.Name = "formatToolStripMenuItem";
            this.formatToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
            this.formatToolStripMenuItem.Text = "Format";
            // 
            // ww
            // 
            this.ww.Name = "ww";
            this.ww.Size = new System.Drawing.Size(132, 22);
            this.ww.Text = "Word Wrap";
            this.ww.Click += new System.EventHandler(this.menuItem16_Click);
            // 
            // fontsToolStripMenuItem
            // 
            this.fontsToolStripMenuItem.Name = "fontsToolStripMenuItem";
            this.fontsToolStripMenuItem.Size = new System.Drawing.Size(132, 22);
            this.fontsToolStripMenuItem.Text = "Fonts...";
            this.fontsToolStripMenuItem.Click += new System.EventHandler(this.mfont_Click);
            // 
            // insertToolStripMenuItem
            // 
            this.insertToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mimages});
            this.insertToolStripMenuItem.Name = "insertToolStripMenuItem";
            this.insertToolStripMenuItem.Size = new System.Drawing.Size(45, 20);
            this.insertToolStripMenuItem.Text = "Insert";
            // 
            // mimages
            // 
            this.mimages.Name = "mimages";
            this.mimages.Size = new System.Drawing.Size(111, 22);
            this.mimages.Text = "Images";
            this.mimages.Click += new System.EventHandler(this.mimages_Click);
            // 
            // helpToolStripMenuItem
            // 
            this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.mreg,
            this.mabout});
            this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
            this.helpToolStripMenuItem.Size = new System.Drawing.Size(41, 20);
            this.helpToolStripMenuItem.Text = "Help";
            // 
            // mreg
            // 
            this.mreg.Name = "mreg";
            this.mreg.Size = new System.Drawing.Size(116, 22);
            this.mreg.Text = "Register";
            this.mreg.Click += new System.EventHandler(this.mreg_Click);
            // 
            // mabout
            // 
            this.mabout.Name = "mabout";
            this.mabout.Size = new System.Drawing.Size(116, 22);
            this.mabout.Text = "About";
            this.mabout.Click += new System.EventHandler(this.mabout_Click);
            // 
            // txt
            // 
            this.txt.AcceptsTab = true;
            this.txt.BackColor = System.Drawing.SystemColors.Window;
            this.txt.ContextMenuStrip = this.contextMenuStrip1;
            this.txt.Dock = System.Windows.Forms.DockStyle.Fill;
            this.txt.Location = new System.Drawing.Point(0, 49);
            this.txt.Name = "txt";
            this.txt.Size = new System.Drawing.Size(641, 142);
            this.txt.TabIndex = 9;
            this.txt.Text = "";
            this.txt.CursorPositionChanged += new System.EventHandler(this.txt_CursorPositionChanged);
            this.txt.SelectionChanged += new System.EventHandler(this.txt_SelectionChanged);
            this.txt.TextChanged += new System.EventHandler(this.txt_TextChanged);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(641, 213);
            this.Controls.Add(this.txt);
            this.Controls.Add(this.statusStrip1);
            this.Controls.Add(this.tool1);
            this.Controls.Add(this.menuStrip1);
            this.IsMdiContainer = true;
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Phan\'s Notepad++";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
            this.tool1.ResumeLayout(false);
            this.tool1.PerformLayout();
            this.statusStrip1.ResumeLayout(false);
            this.statusStrip1.PerformLayout();
            this.contextMenuStrip1.ResumeLayout(false);
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion


        bool dirty = false;
        string fname = "";
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
            menuItem16_Click(sender, e);
           
        }

        private void mnew_Click(object sender, System.EventArgs e)
        {
            checkdirty();
        }



        private void mopen_Click(object sender, System.EventArgs e)
        {
            ofd.Multiselect = false;
            ofd.Filter = "Text Files|*.txt|All files(*.*)|*.*";
            ofd.ShowDialog();
            if (File.Exists(ofd.FileName))
            {
                fname = ofd.FileName;
                StreamReader sr = new StreamReader(fname);
                txt.Text = sr.ReadToEnd();
                dirty = false;
                sr.Close();
                mrecent.AddRecentItem(fname);

            }
        }

        private void txt_TextChanged(object sender, System.EventArgs e)
        {
            dirty = true;
        }

        private void msave_Click(object sender, System.EventArgs e)
        {
            savedata();
        }

        private void savedata()
        {
            if (fname == "")
            {
                sfd.Filter = "Text Files|*.txt";
                DialogResult res = sfd.ShowDialog();
                if (res == DialogResult.Cancel)
                {
                    return;
                }
                fname = sfd.FileName;
                MessageBox.Show(fname);
            }
            StreamWriter sw = new StreamWriter(fname);
            sw.WriteLine(txt.Text);
            sw.Flush();
            sw.Close();
            dirty = false;
            mrecent.AddRecentItem(fname);
        }

        private void checkdirty()
        {
            if (dirty)
            {
                DialogResult click = MessageBox.Show(this, "Bạn có muốn lưu văn bản không?", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (click == DialogResult.Yes)
                {
                    savedata();
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                }
                if (click == DialogResult.No)
                {
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                }
            }
            else
            {
                txt.Text = "";
                fname = "";
            }
        }

        private void msaveas_Click(object sender, System.EventArgs e)
        {
            sfd.Filter = "Text Files|*.txt";
            sfd.ShowDialog();
            fname = sfd.FileName;
            savedata();
            mrecent.AddRecentItem(fname);
        }

        private void mexit_Click(object sender, System.EventArgs e)
        {
            if (dirty)
            {
                DialogResult click = MessageBox.Show(this, "Bạn có muốn lưu văn bản không ?", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (click == DialogResult.Yes)
                {
                    savedata();
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                    this.Dispose();
                }
                if (click == DialogResult.No)
                {
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                    this.Dispose();
                }
                else
                {

                    fname = "";
                }
            }
            else
            {
                this.Dispose();
            }
        }
        private void mpagesetup_Click(object sender, System.EventArgs e)
        {
            PrintDocument pd1 = new PrintDocument();
            pd1.DocumentName = fname;
            psd.Document = pd1;
            psd.ShowDialog();
        }

        private void mprint_Click(object sender, System.EventArgs e)
        {
            PrintDocument pd1 = new PrintDocument();
            pd1.DocumentName = fname;
            pd.Document = pd1;
            pd.AllowSomePages = true;
            pd.AllowPrintToFile = true;
            pd.ShowDialog();
        }

        private void menuItem16_Click(object sender, System.EventArgs e)
        {
            ww.Checked = !(ww.Checked);
            txt.WordWrap = ww.Checked;

        }

        private void mfont_Click(object sender, System.EventArgs e)
        {
            fd.ShowColor = true;
            fd.ShowDialog();
            txt.SelectionFont = fd.Font;
            txt.SelectionColor = fd.Color;
        }

        private void mabout_Click(object sender, System.EventArgs e)
        {
            About nf = new About();
            nf.ShowDialog();
        }

        private void mcut_Click(object sender, System.EventArgs e)
        {
            txt.Cut();
            dirty = true;
        }

        private void mcopy_Click(object sender, System.EventArgs e)
        {
            Clipboard.SetDataObject(txt.SelectedText, true);
        }

        private void mpaste_Click(object sender, System.EventArgs e)
        {
            IDataObject iData = Clipboard.GetDataObject();
            if (iData.GetDataPresent(DataFormats.Text))
            {
                txt.SelectedText = iData.GetData(DataFormats.Text).ToString();

            }
        }

        private void mreg_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show("Đây là phần mềm miễn phí");
        }
        private void ReadDocument()
        {
            string docName = ofd.FileName;
            printDocument1.DocumentName = docName;
            using (FileStream stream = new FileStream(docName, FileMode.Open))
            using (StreamReader reader = new StreamReader(stream))
            {
                documentContents = reader.ReadToEnd();
            }
            stringToPrint = documentContents;
        }
        private void mprintpreview_Click(object sender, EventArgs e)
        {

            ReadDocument();
            printPreviewDialog.Document = printDocument1;
            printPreviewDialog.ShowDialog();
        }

        private void mexit_Click(object sender, FormClosingEventArgs e)
        {
            if (dirty)
            {
                DialogResult click = MessageBox.Show(this, "Bạn có muốn lưu văn bản không ?", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (click == DialogResult.Yes)
                {
                    savedata();
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                    this.Dispose();
                }
                if (click == DialogResult.No)
                {
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                    this.Dispose();
                }
                else
                {

                    fname = "";
                }
            }
        }

        private void tbold_Click(object sender, EventArgs e)
        {

            if (!(txt.Font.Bold))
            {
                txt.Font = new Font(txt.Font, FontStyle.Bold);
            }
        }

        private void titalic_Click(object sender, EventArgs e)
        {

            if (!(txt.Font.Italic))
            {
                txt.Font = new Font(txt.Font, FontStyle.Italic);
            }
        }

        private void tunderline_Click(object sender, EventArgs e)
        {

            if (!(txt.Font.Underline))
            {
                txt.Font = new Font(txt.Font, FontStyle.Underline);
            }
        }

        private void tcenter_Click(object sender, EventArgs e)
        {
            txt.SelectAll();
            txt.SelectionAlignment = HorizontalAlignment.Center;
        }

        private void tleft_Click(object sender, EventArgs e)
        {
            txt.SelectAll();
            txt.SelectionAlignment = HorizontalAlignment.Left;
        }

        private void tright_Click(object sender, EventArgs e)
        {
            txt.SelectAll();
            txt.SelectionAlignment = HorizontalAlignment.Right;
        }

        private void mtool_Click(object sender, EventArgs e)
        {
            mtool.Checked = !(mtool.Checked);
            tool1.Visible = mtool.Checked;
        }

        private void mstatus_Click(object sender, EventArgs e)
        {
            mstatus.Checked = !(mstatus.Checked);
            statusStrip1.Visible = mstatus.Checked;

        }

        private void txt_CursorPositionChanged(object sender, EventArgs e)
        {
            int line = txt.CurrentLine;
            int col = txt.CurrentColumn;


            mlabel.Text = "Line " + line + " Col " + col;

        }

        private void txt_SelectionChanged(object sender, EventArgs e)
        {
            int start = txt.SelectionStart;
            int end = txt.SelectionEnd;
            int length = txt.SelectionLength;

            mlabel.Text = "Start " + start + ", End " + end +
                             ", Length " + length;
        }


        private void mundo_Click(object sender, EventArgs e)
        {
            if (txt.CanUndo == true)
            {
                // Undo the last operation.
                txt.Undo();
                // Clear the undo buffer to prevent last action from being redone.
                txt.ClearUndo();
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (dirty)
            {
                DialogResult click = MessageBox.Show(this, "Bạn có muốn lưu văn bản không ?", "Save", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (click == DialogResult.Yes)
                {
                    savedata();
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                    this.Dispose();
                }
                if (click == DialogResult.No)
                {
                    txt.Text = "";
                    fname = "";
                    dirty = false;
                    this.Dispose();
                }

                else
                {
                    e.Cancel = true;
                    fname = "";
                }
            }
            else
            { this.Dispose(); }
        }


        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            txt.SelectAll();
        }

        private void mrecent_ItemClick(object sender, EventArgs e)
        {
            fname = ((ToolStripDropDownItem)sender).Text;
            StreamReader sr = new StreamReader(fname);
            txt.Text = sr.ReadToEnd();
            dirty = false;
            sr.Close();
            mrecent.AddRecentItem(fname);

        }

        private void findToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_findForm == null || _findForm.IsDisposed)
                _findForm = new Findform.FindForm(txt);
            _findForm.ShowFind(false);
        }

        private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_findForm == null || _findForm.IsDisposed)
            _findForm = new Findform.FindForm(txt);
            _findForm.ShowFind(true);

        }

        private void mimages_Click(object sender, EventArgs e)
        {
            FileDialog fDialog = new OpenFileDialog();
            fDialog.Filter = "Image files|*.jpg|All files|*.*";
            fDialog.CheckFileExists = true;
            fDialog.CheckPathExists = true;
            fDialog.RestoreDirectory = true;
            fDialog.Title = "Choose file to import";
            if (fDialog.ShowDialog() == DialogResult.OK)
            {
                string lstrFile = fDialog.FileName;
                Bitmap myBitmap = new Bitmap(lstrFile);
                // Copy the bitmap to the clipboard.
                Clipboard.SetDataObject(myBitmap);
                DataFormats.Format format = DataFormats.GetFormat(DataFormats.Bitmap);
                // After verifying that the data can be pasted, paste
                if (txt.CanPaste(format))
                {
                    txt.Paste(format);
                }
            }
        }


    }
}
